package com.pri.chat.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.uikit.net.entity.DTBean;
import com.pri.chat.R;
import com.pri.chat.activity.vedio.Utility;

import java.util.List;

import androidx.annotation.Nullable;

/**
 * 描述：添加类的描述
 *
 * @author 金源
 * @time 2020/5/12
 */
public class BangDanVedioAdapter extends BaseQuickAdapter<DTBean, BaseViewHolder> {
    private int actual_width;
    private int type;
    public BangDanVedioAdapter(int layoutResId, @Nullable List<DTBean> data,int type) {
        super(layoutResId, data);
        this.type = type;
    }
    /**
     * 加载视频帧图
     *
     * @param imageView 展示图片view
     * @param url       视频链接
     * @param context   上下文
     */
    public static void loadCover(ImageView imageView, String url, Context context) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.img_default)//图片加载出来前，显示的图片
                .fallback( R.mipmap.img_default) //url为空的时候,显示的图片
                .error(R.mipmap.img_default)
                .transform(new CenterCrop(), new RoundedCorners(10));//图片加载失败后，显示的图片
        Glide.with(context).load(url).apply(options).into(imageView);

    }
    @Override
    protected void convert(BaseViewHolder holder, DTBean item) {
        ImageView vedio_img = holder.getView(R.id.vedio_img);
        holder.setText(R.id.vedio_author,item.getMemberName());
        if(type == 1){
            holder.setText(R.id.vedio_zan, item.getYestodayZanNum()+"");
        }else{
            holder.setText(R.id.vedio_zan, item.getZanNum()+"");
        }
        holder.setText(R.id.vedio_content, item.getContent());
        loadCover(vedio_img,item.getVideoPath() + "?vframe/jpg/offset/1",mContext);
    }
}
